package net.zjitc.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/9/27.
 */
@WebServlet(name = "HttpServletTwo")
public class HttpServletTwo extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response.sendRedirect("/web/threeServlet");//URI
        //转发给four
        //注意：既然问题已经转发给four了，那么自己就不要给客户端响应了
        //请求转发（客户端只请求了一次），地址不变
        //重定向（客户端请求两次），地址发生改变
        /*RequestDispatcher rd=request.getRequestDispatcher("/fourSevlet");
        rd.forward(request,response);*/

        //请求包含
        //响应头在接收的servlet里面设置
        //两个servlet里面的同时响应
        //地址不变
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        out.write("我是two...");
        RequestDispatcher rd=request.getRequestDispatcher("/fourSevlet");
        rd.forward(request,response);

        //请求包含
    }
}
